﻿/*
ParallelPlatform Project - A web platform to distribute and share knowledge
Online Editor - An online tool to create and play animations
Copyright (C) 2011 Daniel Guerrero Martínez & Sergio Rodríguez Lumley

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package Classes{

	/**
	  ShapeShadowList is a list of shapeObjects that stores all necessary
	  data of ShapeObjects (which is the base class itself). Information is
	  accessed specifying ShapeObjects (the class will look for it's shadow
	  by ID)
	*/
	public class ShapeShadowList {
		
		private var shadows:Vector.<ShapeObject>;
		private var lastShadow:ShapeObject;
		
		public function ShapeShadowList(){
			shadows = new Vector.<ShapeObject>();
			lastShadow = null;
		}
		
		/**
		  Pushes shapeObjects in the shadow list
		  @param shap ShapeObject shadow to push in the list
		*/
		public function push(shap:ShapeObject):void{
			shadows.push(shap);
		}
		
		/**
		  Returns the shadow of the specified Shape
		  @param shape ShapeObject which is going to be searched
		  @return ShapeObject shadow of the specified shape, null otherwise
		*/
		public function getShadow(shap:ShapeObject):ShapeObject{
			var id:String = shap.getFullID();
			var shadow:ShapeObject = null;
			if(lastShadow != null && lastShadow.getFullID() == id){
				shadow = lastShadow;
			}else{
				// Look for it
				for(var i:uint =0; i<shadows.length && shadow == null; ++i){
					if(shadows[i].getFullID() == id) shadow = shadows[i];
				}
			}
			return shadow;
		}
		
		public function clear():void{
			while(shadows.length > 0){
				shadows.pop();
			}
		}
		
		public function printString():String{
			var str:String = new String();
			for(var i:uint = 0; i<shadows.length; ++i){
				str += " ["+shadows[i].getFullID() +"]";
			}
			return str;
		}
		
		//// ********* PRIVATE FUNCTIONS ********* ////
		
	}
}